package org.jeecg.modules.system.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.system.entity.DeptInfo;
import org.jeecg.modules.system.mapper.DeptInfoMapper;
import org.jeecg.modules.system.model.SysDepartTreeModel;
import org.jeecg.modules.system.service.IDeptInfoService;
import org.jeecg.modules.system.util.LdarFindsDeptsChildrenUtil;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: dept_info
 * @Author: jeecg-boot
 * @Date:   2023-10-20
 * @Version: V1.0
 */
@Service

public class DeptInfoServiceImpl extends ServiceImpl<DeptInfoMapper, DeptInfo> implements IDeptInfoService {

    @Override
    public List<DeptInfo> getLocationDept(String companyCode) {
        return baseMapper.getLocationDept(companyCode);
    }
    /**
     * queryTreeList 根据部门id查询,前端回显调用
     */
    @Override
    public List<SysDepartTreeModel> queryTreeList(String ids) {
        LambdaQueryWrapper<DeptInfo> query = new LambdaQueryWrapper<DeptInfo>();
        if(oConvertUtils.isNotEmpty(ids)){
            query.in(true,DeptInfo::getId,ids.split(","));
        }
        query.orderByAsc(DeptInfo::getCode);
        List<DeptInfo> list= this.list(query);
        List<SysDepartTreeModel> listResult = LdarFindsDeptsChildrenUtil.wrapTreeDataToTreeList(list);
        return  listResult;

    }
}
